// pages/mine/mine.js
import { mineApi } from "@/utils/request/api/mine";
const { imgUrl } = getApp().globalData;
Page({
  /**
   * 页面的初始数据
   */
  data: {
    imgUrl: imgUrl + "mine/",
    // 个人信息
    myInfo: {
      id: -1, //id为0是新增，不为0是修改
      user_type: 1, //用户类型，1-普通用户，2-企业用户
      mobile: "", //手机号码
      email: "", //电子邮箱，比如 example@qq.com
      password: "", //密码
      user_no: "", //账户ID号
      real_name: "", //真名
      nick_name: "", //昵称
      avatar: "", //头像
      is_cancel: false, //是否注销
      is_expert: false, //是否认证为专家
      is_course_note: false, //是否课程笔记禁言
      is_course_comment: false, //是否课程评论禁言
      address: "", //地区
      industry: "", //行业
      signature: "", //签名
      status: true, //用户账号状态	0：禁用	1：正常
      note: "",
      open_id: "", //微信用户唯一标识
      followers_count: 1, //粉丝数量
      following_count: 1, //关注数量
      likes_count: 0, //获赞数量
      created_ip: "",
      coin_balance: 100, //金币余额
      coin_expense: 0, //金币支出总额
      vip_type: 0, //vip类型，1-周卡，2-月卡，3-季度卡，4-年卡，5-超级会员
      vip_expire_time: 0, //vip到期时间，unix秒数
      created_at: "",
      updated_at: "",
      company_check_status: "", //企业认证状态，0-未认证，1-认证中，2-认证通过，3-认证失败
    },
    // 签到状态
    singStatus: [],
    showZan: false
  },

  toSetting() {
    wx.navigateTo({
      url: "/pages/mine/person/person",
    });
  },
  toSpending() {
    wx.navigateTo({
      url: "/pages/mine/spendingRecords/spendingRecords",
    });
  },
  toMyClass() {
    wx.navigateTo({
      url: "/pages/mine/myClass/myClass",
    });
  },
  toCompany() {
    if (this.data.myInfo.company_check_status == 2) {
      wx.navigateTo({
        url: "/pages/mine/myFirm/myCompany/myCompany",
      });
    } else {
      wx.navigateTo({
        url: "/pages/mine/myFirm/company/company",
      });
    }
  },
  toMonitor() {
    wx.navigateTo({
      url: "/pages/mine/enterpriseMonitor/enterpriseMonitor",
    });
  },
  toDocument() {
    wx.navigateTo({
      url: "/pages/mine/myDocument/myDocument",
    });
  },
  toProject() {
    wx.navigateTo({
      url: "/pages/mine/myProject/myProject",
    });
  },
  toSubscription() {
    wx.navigateTo({
      url: "/pages/mine/mySubscription/mySubscription",
    });
  },
  toKb() {
    wx.navigateTo({
      url: "/pages/mine/coinbase/coinbase",
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    mineApi
      .getMineUserInfo()
      .then((res) => {
        if (res.data) {
          this.setData({
            myInfo: res.data,
          }, () => {
            wx.setStorageSync('myInfo', res.data)
          });
        }
      });

    this.signStatus();
  },

  // 签到 打卡
  toSinged() {
    mineApi.userSignIn().then((res) => {
      console.log('sign in res === ', res.data);
      this.signStatus();
    });
  },

  // 查看签到的状态
  signStatus() {
    mineApi.getSingInfo({}).then((res) => {
      console.log('res res === ', res.data);
      if (res.data.today_signed === false) {
        this.toSinged();
      }
      this.setData({
        singStatus: res.data.week_status,
      });
      console.log('res.datra.we === ', this.data.singStatus);
    });
  },
  onCloseZan() {
    this.setData({
      showZan: false
    })
  },
  showZanPop() {
    this.setData({
      showZan: true
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
  toForumCenter() {
    wx.navigateTo({
      url: "/pages/forum/homepage/homepage",
    });
  },
  toCollect() {
    wx.navigateTo({
      url: "/pages/mine/collect/collect",
    });
  },
  toFans() {
    wx.navigateTo({
      url: "/pages/mine/fans/fans",
    });
  },
  toFollow() {
    wx.navigateTo({
      url: "/pages/mine/follow/follow",
    });
  },
  toSetup() {
    wx.navigateTo({
      url: "/pages/mine/setup/setup",
    });
  },
});
